
#ifndef SMSMONITOR_H_
#define SMSMONITOR_H_

#include <MSVAPI.h>
#include <smut.h>
#include <MIUTSET.h>
#include <SMSCLNT.H>
#include <MTMUIBAS.H>
#include <mtuireg.h>
#include <aknglobalnote.h>
#include <avkon.rsg>
#include <avkon.hrh>
#include <apgcli.h>

#include "globalobserver.h"
#include "ForegroundObserver.h"

class SMSMonitor : public MMsvSessionObserver, public CActive
{
	public:
		
		/**
		 * Destructor
		 * @return - NONE
		 * */
		~SMSMonitor();
		
		/**
		 * Public interface for the Singleton pattern
		 * @return - NONE
		 * */
		static SMSMonitor* GetInstance();
		
		/**
		 * This function starts the application
		 * @return - NONE
		 * */
		void Start();
		
		/**
		 * This function stops the application
		 * @return - NONE 
		 * */
		void Stop();
		
		/**
		 * This function opens the received message in the standard message viewer
		 * @return - NONE
		 * */
		void OpenMsg();
		
		/**
		 * This function opens the received message in the standard message viewer
		 * @return - NONE
		 * */
		void SendEvent();
		
		/**
		 * This function indicates if the application's global note is displayed
		 * @return - true if the note is displayed
		 * */
		bool IsNoteDisplayed();
		
		/**
		 * This functions sets the value of the boolean which indicates if the global note is displayed
		 * @return - NONE
		 * */
		void SetNoteDisplayed(bool aValue);
		
		/**
		 * This functions deltes the received message
		 * @return - NONE
		 * */
		void DeleteMessage();
		
		/**
		 * This function launches the messaging application
		 * @return - NONE
		 * */
		void LaunchMessaging();
	private:
		
		/**
		 * Constructor
		 * @return - NONE
		 * */
		SMSMonitor();
		
		/**
		 * Second level constructor
		 * @return - NONE
		 * */
		void ConstructL();
		
		/**
		 * This function is called by the platform upon completion of an asynchronous request
		 * @return - NONE
		 * */
		void RunL();
		
		/**
		 * This function is called by the platform to cancel any asynchronous request
		 * @return - NONE
		 * */
		void DoCancel();
		
		/**
		 * Symbian style constructor
		 * @return - NONE
		 * */
		static void NewL();
		
		/**
		 * Just in case we need such a function in future that marks a message as "read"
		 * @return - NONE
		 * */
		void MarkMsgAsRead();
		
		
		/**
		 * This function handles the message server notifications
		 * @return - NONE
		 * */
		void HandleSessionEventL(TMsvSessionEvent aEvent, TAny *aArg1, TAny *aArg2, TAny *aArg3);
		
		/**
		 * This function shows the global note displayed to the user on receipt of a message
		 * @return - NONE
		 * */
		void ShowGlobalNoteL(bool);
		
		/**
		 * This functions checks if any unread item(s) are present in the device's Inbox
		 * @return true if Unread item(s) are present, false otherwise
		 * */
		bool IsUnreadItem();
	
	private:
		static SMSMonitor *self;
		CMsvSession* iSession;
		CClientMtmRegistry* iMtmRegistry;         //   client MTM registry
		CSmsClientMtm* iSmsMtm;
		CBaseMtm* iBaseMtm;
		CMtmUiRegistry* iMtmUiReg;
		CMsvOperationWait* iWaiter;
		CMsvOperation* iOperation;
		CAknGlobalNote* iNote;
		CGlobalObserver* iObserver;
		TMsvId iMessageId;
		TBuf<15> iPhoneNumber;
		bool iApplicationRunning;
		bool iNoteDisplayed;
		bool iMsgReceived;
		bool iMsgSendingAttempted;
		CForegroundObserver* iForegroundObserver;
};

#endif
